package com.api.shopapi.service.impl;

import com.api.shopapi.entity.Nurse;
import com.api.shopapi.entity.User;
import com.api.shopapi.entity.dto.NurseDTO;
import com.api.shopapi.mapper.NurseMapper;
import com.api.shopapi.service.NurseService;
import com.api.shopapi.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("NurseServiceImplOne")
public class NurseServiceImpl  implements NurseService {

    @Autowired
    private NurseMapper nurseMapper;

    @Autowired
    @Qualifier("UserServiceImplOne")
    private UserService userService;

    @Override
    public List<NurseDTO> getList(String institutionCode) {
        return nurseMapper.getList(institutionCode);
    }

    @Override
    public int insert(Nurse nurse) {
        return nurseMapper.insert(nurse);
    }

    @Override
    @Transactional
    public int updateByNurseCode(User user,Nurse nurse) {
        userService.update(user);
        return nurseMapper.updateByNurseCode(nurse);
    }

    @Override
    public int delete(String nurseCode) {
        return nurseMapper.delete(nurseCode);
    }

    @Override
    public Nurse getByNurseCode(String nurseCode) {
        return nurseMapper.getByNurseCode(nurseCode);
    }

    @Override
    @Transactional
    public int regInsert(User user, Nurse nurse) {
        userService.insert(user);
        return nurseMapper.insert(nurse);
    }

    @Override
    public Nurse getByUserCode(String userCode) {
        return nurseMapper.getByUserCode(userCode);
    }

    @Override
    public PageInfo<NurseDTO> getPageList(int pageIndex, int pageSize, String institutionCode, String name, int status) {
        PageHelper.startPage(pageIndex, pageSize);
        List<NurseDTO> nurseDTOList = nurseMapper.getPageList(institutionCode,name,status);
        PageInfo<NurseDTO> pageInfo = new PageInfo<>(nurseDTOList);
        return pageInfo;
    }


    @Override
    public
    PageInfo<NurseDTO> pageByGovCode(int pageIndex, int pageSize, String governmentCode){
        PageHelper.startPage(pageIndex, pageSize);
        List<NurseDTO> nurseDTOList = nurseMapper.listByGovCode(governmentCode);
        PageInfo<NurseDTO> pageInfo = new PageInfo<>(nurseDTOList);
        return pageInfo;
    }


    @Override
    public
    PageInfo<Nurse> pageByGovCodeInsCode(int pageIndex, int pageSize,
                                         String governmentCode, String institutionCode){
        PageHelper.startPage(pageIndex, pageSize);
        List<Nurse> nurseDTOList = nurseMapper.listByGovCodeInsCode(governmentCode,institutionCode);
        PageInfo<Nurse> pageInfo = new PageInfo<>(nurseDTOList);
        return pageInfo;
    }

    @Override
    public
    List<NurseDTO> listByGovCode(String governmentCode){
        return nurseMapper.listByGovCode(governmentCode);
    }

    @Override
    public
    List<Nurse> listByInsCode(String institutionCode){
        return nurseMapper.listByInsCode(institutionCode);
    }

}
